package edu.northwestern.cbits.purple_robot_manager.models.trees;
import java.util.Map;
/**
* Abstract class that defines the required elements of a tree node class.
*/
public abstract class TreeNode
{
public static final String NAME = "name";
private String _name = null;
public TreeNode(String name)
{
this._name = name;
}
public String getName()
{
return this._name;
}
/**
* Returns a prediction for the given state of the world as interpreted by
* the model
*
* @param features
* Features representing the current state of the world.
*
* @return Map containing the prediction generated by the model as well as
* any associated metadata.
*
* @throws TreeNodeException
* Thrown if an error occurs evaluating the model. Refer to the
* exception's message for details.
*/
public abstract Map<String, Object> fetchPrediction(Map<String, Object> features) throws TreeNodeException;
/**
* Encapsulates tree-related exceptions.
*/
public static class TreeNodeException extends Exception
{
public TreeNodeException(String message)
{
super(message);
}
private static final long serialVersionUID = 3671610661977748070L;
}
/**
* Returns a nested presentation of the tree node and any descendants (if
* applicable.
*
* @param indent
* Number of levels to indent the tree. 1 level corresponds to 2
* spaces.
*
* @return String representation of the tree suitable for human
* interpretation.
*
* @throws TreeNodeException
* Thrown on an error encountered evaluating the tree.
*/
public abstract String toString(int indent) throws TreeNodeException;
/**
* Equivalent to calling toString(0).
*
* @see java.lang.Object#toString()
*/
public String toString()
{
try
{
return this.toString(0);
}
catch (TreeNodeException e)
{
throw new RuntimeException(e);
}
}
}